class Solution {
public:
    /*
    用两个指针low和high指向边界
    如果*low+*high=sum,说明找到了
    *low+*high<sum,low++;
    *low+*high>sum,high--;
    */
    vector<int> FindNumbersWithSum(vector<int> array,int sum) {
        vector<int> ans;
        if(array.empty())
            return ans;
        auto low=array.begin();
        auto high=array.end()-1;
        while(low<high)
        {
            if(*low+*high<sum) ++low;
            else if(*low+*high>sum) --high;
            else if(*low+*high==sum)
            {
                ans.push_back(*low);
                ans.push_back(*high);
                break;
            }
        }
        return ans;
    }
};